<template>
  <el-tooltip placement="top" effect="customized" v-model:visible="visible">
    <template #content>
      <span>{{ t('component.table.settingDens') }}</span>
    </template>

    <el-dropdown ref="dropdown" trigger="contextmenu" @command="handleCommand">
      <el-button class="svg-Btn" text @mouseenter="visible = true" @click="visible = false; showDropdown()"
        @mouseleave="visible = false">
        <template #icon>
          <SvgIcon icon-class="density" :size="20"></SvgIcon>
        </template>
      </el-button>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item command="default">默认</el-dropdown-item>
          <el-dropdown-item command="large">大的</el-dropdown-item>
          <el-dropdown-item command="small">小的</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </el-tooltip>
</template>

<script lang="ts" setup>
import { useI18n } from '@/hooks/web/useI18n'
import { ref } from 'vue'
import { useTableContext } from '../../hooks/useTableContext'

const dropdown = ref()
const visible = ref(false)
const { t } = useI18n()
const table = useTableContext()

const showDropdown = () => {
  dropdown.value.handleOpen()
}


const handleCommand = (command: string | number | object) => {
  table.setProps({ size: command })
}
</script>